package com.itheima.leyou.search.controller;

import com.itheima.leyou.search.dto.SearchParamDTO;
import com.itheima.leyou.search.entity.Goods;
import com.itheima.leyou.service.SearchService;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods")
public class SearchController {

    @Autowired
    private SearchService seachService;

    /**
     * 自动补全
     * @param key
     * @return
     */
    @GetMapping("/suggestion")
    public Mono<List<String>> getSuggestion(
            @RequestParam("key")String key){
        return seachService.getSuggestion(key);

    }


    /**
     * 普通搜索查询
     * @param searchParamDTO
     * @return
     */
    @PostMapping("/list")
    public Mono<PageInfo<Goods>>  generateSearch(
            @RequestBody  SearchParamDTO searchParamDTO){
        Mono<PageInfo<Goods>> pageInfoMono = seachService.generateSearch(searchParamDTO);
        return pageInfoMono;
    }


    //filter

    @PostMapping("/filter")
    public Mono<Map<String,List<?>>>  searchFilter(
            @RequestBody  SearchParamDTO searchParamDTO){
        return   seachService.searchFilter(searchParamDTO);

    }
}
